import type { App } from 'vue';
import { createRouter, createWebHistory } from 'vue-router';

import { constantRoutes as staticRoutes } from './constant';

import { templateRoutes } from './template';
import { abilityRoutes } from './ability';

// 开发路由
const developmentRoutes = [...templateRoutes, ...abilityRoutes];

// 静态路由 开发环境下会加载开发路由
export const constantRoutes = [...staticRoutes].concat(import.meta.env.DEV ? developmentRoutes : []);

// 所有的本地路由表
export const completeRoutes = [
  ...constantRoutes,
  // 新增的路由配置添加在此处
];

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 全局注册 router
export function setupRouter(app: App<Element>) {
  app.use(router);
}

export default router;
